{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.instrument import IRCMSSpreadOption\n",
    "from gs_quant.markets import PricingContext\n",
    "from gs_quant.markets.portfolio import Portfolio\n",
    "from gs_quant.risk import IRAnnualImpliedVol, Price\n",
    "import pandas as pd\n",
    "\n",
    "pd.options.display.float_format = '{:,.4f}'.format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# instantiate session if not running in jupyter hub - external clients will have a client_id and secret.  Internal clients will use SSO\n",
    "from gs_quant.session import GsSession\n",
    "GsSession.use(client_id=None, client_secret=None, scopes=('run_analytics',)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define a set of pairs and option expiries\n",
    "pairs = [('5y','2y'), ('10y','2y'), ('30y','2y'), ('30y','5y'), ('30y','10y')]\n",
    "expiries = ['1m', '2m', '3m', '6m', '9m', '1y', '18m', '2y', '3y', '4y', '5y', '7y', '10y', '12y', '15y', '20y']\n",
    "portfolios = Portfolio([Portfolio([\n",
    "    IRCMSSpreadOption(termination_date=e, notional_currency='EUR', notional_amount=10000, index1_tenor=p[0], index2_tenor=p[1], \n",
    "                      name='{}_{}{}'.format(e, p[0], p[1]))for e in expiries]) for p in pairs])\n",
    "\n",
    "# price our list of portfolios\n",
    "with PricingContext():\n",
    "    result_p = portfolios.calc(Price)\n",
    "    result_v = portfolios.calc(IRAnnualImpliedVol)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prices = result_p.to_frame() * 100\n",
    "prices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vols = result_v.to_frame() * 10000\n",
    "vols"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
